<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: member_activate.php 25756 2011-11-22 02:47:45Z zhangguosheng $
 */

if( !defined( 'IN_DISCUZ' ) ){
	exit('Access Denied');
}

$aid	= 0;
$catid = 999;

require_once libfile( 'function/upload' );
require_once libfile( 'function/spacecp' );
require_once libfile( 'function/home' );
$swfconfig	= getuploadconfig( $_G['uid'], 0, false );
$albums		= getalbums( $_G['uid'] );
	
$options		= array( 'list', 'info', 'mod', 'add' );
$op				= in_array( $_GET['op'], $options ) ? $_GET['op'] : 'list';
if( empty( $_G['master'] ) )
	header( "Location:master.php" );
if( $op == 'list' ){$_GET['page']	= $_GET['page'] ? $_GET['page'] : 1;
	$limit			= 25;
	$s_limit		= ( $_GET['page'] - 1 ) * $limit . ", {$limit}";
	$where			= "`a`.`mid` = '{$mid}'";
	$where			.= empty( $_GET['name'] ) ? '' : " AND `a`.`title` LIKE '%{$_GET['name']}%'";
	$messageLs		= C::t( 'master_message' )->fetch_all( $where, $s_limit, "`updtime` DESC, `id`" );
	$page			= multi( $messageLs['num'], $limit, $_GET['page'], "master.php?mod=message&mid={$mid}" );
	include_once template("master/message_list");
}elseif( $op == 'info' ){
	if( empty( $_GET['id'] ) )
		showmessage( '抱歉，您要查看的内容不存在。' );
	$messageInfo	= C::t( 'master_message' )->fetch( $_GET['id'] );
	if( empty( $messageInfo ) )
		showmessage( '抱歉，您要查看的内容不存在。' );
	include_once template("master/message_info");
}elseif( $op == 'add' ){
	if( empty( $_G['adminid'] ) && ( empty( $_G['uid'] ) || $_G['uid'] != $_G['master']['uid'] ) )
		showmessage( '抱歉，您无权使用此功能' );
	if( empty( $_GET['mid'] ) )
		showmessage( '请选择信息对应的玉雕大师' );
	if( submitcheck( "articlesubmit", 0, $seccodecheck, $secqaacheck ) ){
		if( empty( $_GET['title'] ) )
			showmessage( '请输入文章标题' );

		if( empty( $_POST['summary'] ) )
			$_POST['summary']	= preg_replace( "/(\s|\<strong\>##########NextPage(\[title=.*?\])?##########\<\/strong\>)+/", ' ', $_POST['content'] );
		$summary	= portalcp_get_summary( $_GET['summary'] );
		$summary	= censor($summary);
		$content	= getstr( $_GET['content'], 0, 0, 0, 0, 1 );
		$content	= censor( $content );
		if( empty( $_GET['conver'] ) ){
			if( preg_match( '/<img(.*?)src="(.*?)"(.*?)>/i', $content, $result ) ){
				$_GET['conver']	= $result[2];
			}
		}
		$data		= array(
			'mid'		=> $_GET['mid'],
			'title'		=> trim( $_GET['title'] ),
			'type'		=> '1',
			'content'	=> $content,
			'summary'	=> $summary,
		);
		
		$id = C::t( 'master_message' )->insert( $data, 1 );
		
		if( !$id )
			showmessage( '添加失败' );
		$msg = array(
				'mod'	=> "master.php?mod=message&op=mod&mid={$_GET['mid']}&id={$id}",
				'new'	=> "master.php?mod=message&op=add&mid={$_GET['mid']}",
				'view'	=> "master.php?mod=message&op=info&mid={$_GET['mid']}&id={$id}",
		);
		include_once template( "master/master_success" );dexit();
	}else
		include_once template("master/message_edit");
}elseif( $op == 'mod' ){
	if( empty( $_G['adminid'] ) && ( empty( $_G['uid'] ) || $_G['uid'] != $_G['master']['uid'] ) )
		showmessage( '抱歉，您无权使用此功能' );
	if( empty( $_GET['mid'] ) )
		showmessage( '请选择作品对应的玉雕大师' );
	if( empty( $_GET['id'] ) )
		showmessage( '请选择要修改的作品' );
	$messageInfo	= C::t( 'master_message' )->fetch( $_GET['id'] );
	if( empty( $messageInfo ) )
		showmessage( '请选择要修改的作品' );
	if( submitcheck( "articlesubmit", 0, $seccodecheck, $secqaacheck ) ){
		if( empty( $_GET['title'] ) )
			showmessage( '请输入作品名称' );

		if( empty( $_POST['summary'] ) )
			$_POST['summary']	= preg_replace( "/(\s|\<strong\>##########NextPage(\[title=.*?\])?##########\<\/strong\>)+/", ' ', $_POST['content'] );
		$summary	= portalcp_get_summary( $_GET['summary'] );
		$summary	= censor($summary);
		$content	= getstr( $_GET['content'], 0, 0, 0, 0, 1 );
		$content	= censor( $content );
		if( empty( $_GET['conver'] ) ){
			if( preg_match( '/<img(.*?)src="(.*?)"(.*?)>/i', $content, $result ) ){
				$_GET['conver']	= $result[2];
			}
		}
		$data		= array(
			'mid'		=> $_GET['mid'],
			'title'		=> trim( $_GET['title'] ),
			'type'		=> '1',
			'content'	=> $content,
			'summary'	=> $summary,
		);
		C::t( 'master_message' )->update( $_GET['id'], $data );
		$msg = array(
				'mod'	=> "master.php?mod=message&op=mod&mid={$_GET['mid']}&id={$_GET['id']}",
				'new'	=> "master.php?mod=message&op=add&mid={$_GET['mid']}",
				'view'	=> "master.php?mod=message&op=info&mid={$_GET['mid']}&id={$_GET['id']}",
		);
		include_once template( "master/master_success" );dexit();
	}else
		include_once template( "master/message_edit" );
}


function portalcp_get_summary( $message ) {
	$message = preg_replace( array("/\[attach\].*?\[\/attach\]/", "/\&[a-z]+\;/i", "/\<script.*?\<\/script\>/"), '', $message );
	$message = preg_replace( "/\[.*?\]/", '', $message );
	$message = getstr( strip_tags( $message ), 200 );
	return $message;
}
?>